// #include "../src/windows.hpp"
#include "../src/common.h"
#include "../src/image.hpp"
// #include <iostream>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <chrono>


void apply_surface( int x, int y, SDL_Surface* src, SDL_Surface* dst ) {
	//Temporary rectangle to hold the offsets
	SDL_Rect offset;
	offset.x = x;
	offset.y = y;
	SDL_BlitSurface(src, nullptr, dst, &offset);
}

int main () {

	TTF_Init ();
	auto font = TTF_OpenFont ("res/test.ttf", 46);
	if (!font) {
		std::cerr << "TTF_OpenFont error:" << TTF_GetError ();
		SDL_Quit ();
		return -1;
	}
	SDL_Surface* msg;
	WINDOW win (800, 600);
	IMAGE pic (win, 400, 400);
	int x, y;
	int quit = 1;
	SDL_Event event;
	win.setDrawFontRotation (40);
	while (quit) {
		SDL_WaitEvent(&event);
		switch (event.type) {
			case SDL_QUIT://退出事件
				SDL_Log("quit");
				quit = 0;
				SDL_Quit ();
				return 0;
				break;
			default:
				SDL_Log ("x: %d\ty: %d", x, y);
				// SDL_Log("event type:%d", event.type);
		}
		SDL_GetMouseState (&x, &y);
		msg = TTF_RenderText_Solid (font, "Hello World", {255, 255, 255});
		if (msg) {
			apply_surface (x, y, msg, win.getSurface ());
			win.update ();
		}
		win.drawString (x, y + 40, "Hello World");
	}


	getchar ();
	SDL_Quit ();

	return 0;
}